package de.bht.netviz.ipsaver.lookup.config;

import de.bht.netviz.ipsaver.lookup.dao.FreeGeoAdaptor;
import de.bht.netviz.ipsaver.lookup.dao.FreeGeoLookupDataJpaController;
import de.bht.netviz.ipsaver.lookup.dao.GeoPluginAdaptor;
import de.bht.netviz.ipsaver.lookup.dao.GeoPluginLookupDataJpaController;
import de.bht.netviz.ipsaver.lookup.dao.ILookupServiceJpaController;
import de.bht.netviz.ipsaver.lookup.service.FreeGeoLookupService;
import de.bht.netviz.ipsaver.lookup.service.GeoPluginLookupService;
import de.bht.netviz.ipsaver.lookup.service.ILookupService;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;

/**
 * Factory zur dynamischen Auswahl des korrekten JPA Controllers, je nach verwendetem
 * IP Locator Dienst.
 * @author Marius Hentschel
 * @since  2012/11/05
 */
public class LookupServiceControllerAdaptorFactory {
   public static ILookupServiceJpaController getController( ILookupService service ) {
      ILookupServiceJpaController retVal = null;
      EntityManagerFactory emf = Persistence.createEntityManagerFactory( IPSaverConfig.getPERS_UNIT_NAME() );
      
      if( service instanceof GeoPluginLookupService ) {
         retVal = new GeoPluginAdaptor( new GeoPluginLookupDataJpaController( emf ));
      } else if( service instanceof FreeGeoLookupService ) {
         retVal = new FreeGeoAdaptor( new FreeGeoLookupDataJpaController( emf ));
      }
      return retVal;
   }
}
